package nio;

import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

/**
 * @author RJA
 * @version V1.0
 * @Title: nio.demo_1
 * @Description:
 * @date 2019/9/6 14:49
 */
public class NioTest10 {
    public static void main(String[] args) throws Exception{
        RandomAccessFile randomAccessFile = new RandomAccessFile("test09.txt","rw");
        FileChannel fileChannel = randomAccessFile.getChannel();

        FileLock fileLock = fileChannel.lock(3,6,true);
        System.out.println("valid:" + fileLock.isValid());
        System.out.println("locktype:" + fileLock.isShared());

        fileLock.release();
        randomAccessFile.close();
    }
}
